-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate VPA CRD v1 from types.go #3606
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks interesting.
My main question is, what will happen for an existing vpa deployment that used the old yaml? Is the generated yaml compatible, so that the existing vpa objects will continue working?
fi | ||
|
||
# The following commands always returns an error because controller-gen does not accept keys other than strings. | ||
${CONTROLLER_GEN} ${CRD_OPTS} paths="${APIS_PATH}/..." output:crd:dir=${WORKSPACE} ||: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way we can check for this specific error? What will happen if the generator fails for a different error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, controller-gen does not support feature to check for specific error or ignore only the specific error, but we can find other errors in the output. If the generator fails for a different error, this script will also output other than map keys must be strings
.
$ hack/generate-crd-yaml.sh
/Users/ladicle/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go:360:20: map keys must be strings, not int
/Users/ladicle/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2/types.go:340:20: map keys must be strings, not int
Error: not all generators ran successfully
run `controller-gen crd:trivialVersions=false,allowDangerousTypes=true paths=/Users/ladicle/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/... output:crd:dir=/var/folders/p_/hzm_gclx7vs5cdbfbzpl0s4w0000gn/T/tmp.Cytp8OtyCn -w` to see all available markers, or `controller-gen crd:trivialVersions=false,allowDangerousTypes=true paths=/Users/ladicle/src/k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/... output:crd:dir=/var/folders/p_/hzm_gclx7vs5cdbfbzpl0s4w0000gn/T/tmp.Cytp8OtyCn -h` for usage
Another way is to grep the controller-gen output and display a warning message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a not-overly complicated way to indicate that something other went wrong, I would really like to see it. Otherwise it might get really confusing for someone encountering issues.
@@ -3,4 +3,4 @@ resources: | |||
- recommender-deployment.yaml | |||
- updater-deployment.yaml | |||
- vpa-rbac.yaml | |||
- vpa-v1-crd.yaml | |||
- vpa-v1-crd-v1.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe vpa-v1-crd-gen.yaml
Yes, there is no change in the yaml field, so it's compatible. If you applied to a cluster which has old vpa, When the first time to install vpa, like this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, left a couple more minor comments.
@@ -39,8 +39,17 @@ if [ $# -gt 2 ]; then | |||
exit 1 | |||
fi | |||
|
|||
SEMVER_RE='v[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' | |||
K8S_VERSION=$(kubectl version --short=true|grep Server|awk '{print $3}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to check the k8s version - the 0.9 VPA requires 1.16 anyway: https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler#compatibility
COMPONENTS="vpa-v1-crd ${COMPONENTS}" | ||
else | ||
COMPONENTS="vpa-v1-crd-v1-gen ${COMPONENTS}" | ||
fi | ||
case ${ACTION} in | ||
delete|diff|print) COMPONENTS+=" vpa-beta2-crd" ;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is that we need to add vpa-v1-crd here to delete it on vpa-down.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove version-specific processing and specify only vpa-v1-crd-v1-gen; although the versions of the CRD are different, they define the same VPA resources, we cand delete CR using either crd-v1-crd or crd-v1-crd-gen files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sence, thank you
fi | ||
|
||
# The following commands always returns an error because controller-gen does not accept keys other than strings. | ||
${CONTROLLER_GEN} ${CRD_OPTS} paths="${APIS_PATH}/..." output:crd:dir=${WORKSPACE} ||: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a not-overly complicated way to indicate that something other went wrong, I would really like to see it. Otherwise it might get really confusing for someone encountering issues.
I don't think this is the right approach, since we are preserving a mistake. I recommend that @kubernetes/sig-api-machinery-api-reviews is consulted for this one. Thanks. I think one way this can addressed is that introduce a new version of this api that has the correct data types. Then use CRD conversion webhook to migrate to that version. |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
I agree with @tamalsaha that we should finally modify the VPA APIs to use string as the map key. Disabling validation of the |
I agree with @Ladicle on not mixing too many changes at once. I think there is already a lot of benefit from moving to the controller-gen here and the issue with incorrectly defined field is a separate one, which needs to be approached with a lot of care to not break existing users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good.
Small naming change and we should be good to merge.
@@ -3,4 +3,4 @@ resources: | |||
- recommender-deployment.yaml | |||
- updater-deployment.yaml | |||
- vpa-rbac.yaml | |||
- vpa-v1-crd.yaml | |||
- vpa-v1-crd-v1-gen.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vpa-v1-crd-gen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recheck all file names and unified to vpa-v1-crd-gen. Also, recreated the CRD manifest.
@@ -73,7 +73,7 @@ for i in ${COMPONENTS}; do | |||
ALL_ARCHITECTURES=amd64 make --directory ${SCRIPT_ROOT}/pkg/${i} release | |||
done | |||
|
|||
kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-v1-crd.yaml | |||
kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-v1-crd-v1-gen.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vpa-v1-crd-gen
Looks good, thanks a lot! Can you squash the commits? Then it's ready to go :) |
Thank you for reviewing :) I've squashed all commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bskiba, Ladicle, mwielgus The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
ref: #3508
In this PR, I generate CRD v1 from types.go using
[email protected]
.Here are some things to note:
allowDangerousType
option is enabled. (ref: Support floats? kubernetes-sigs/controller-tools#245 (comment))viacheckpoint
have int map key that is not supported in JSON, so disable validation only for that field. Along with this, generation script ignores error returned by controller-gen. (ref: CRD: bad map key type: map keys must be strings #3574)metav1.ObjectMeta
does not accept optional tags, so remove it from types.go.